<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="auth" uri="http://www.jiyinit.com/authTag"%>

<div class="container">
    <table class="table-bordered" style="margin: 200px auto;">
        <tr>
            <td>
                <button id="deployFilesBtn" class="btn btn-primary" type="button">
                    <i class="fa fa-cog"></i> 部署上线包
                </button>
            </td>
            <td>
                <button id="reductionBtn" class="btn btn-primary" type="button">
                    <i class="fa fa-cog"></i> 还原到备份版本
                </button>
            </td>
            <td>
                <button id="restartTomcatBtn" class="btn btn-primary" type="button">
                    <i class="fa fa-cog"></i> 重启tomcat服务
                </button>
            </td>
        </tr>
    </table>
    <%--<div class="manage-button">
        <button id="deployFilesBtn" class="btn btn-primary" type="button">
            <i class="fa fa-cog"></i> 部署上线包
        </button>
        <button id="restartTomcatBtn" class="btn btn-primary" type="button">
            <i class="fa fa-cog"></i> 重启tomcat服务
        </button>
    </div>--%>
</div>

<script>
    layer.config({
        resize: false,
    });

    var title = "提示信息";
    var time_second;//秒数
    var time_task;//定时任务

    $("#deployFilesBtn").on("click", function () {
        alertInfo("该功能已停用");
        disableBtns();
        layer.open({
            type: 2,
            title: '部署上线包',
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['623px', '350px'],
            content: '${basePath}/deploy/toDeployFiles',
            end: function () {
                unDisableBtns();
            }
        });
    });

    $("#reductionBtn").on("click", function () {
        alertInfo("该功能已停用");
        return false;
    });


    $("#restartTomcatBtn").on("click", function () {
        disableBtns();
        layer.confirm('确定要重启tomcat服务？', {
            title: "提示",
            icon: 3,
            closeBtn: 0,
            btn: ['确定','取消'] //按钮
        }, function(){
            $.ajax({
                url: "${basePath}/deploy/restartTomcat",
                type: "POST",
                dataType: "json",
                success: function (data) {
                    unDisableBtns();
                    if(data.status == '0'){
                        successInfo("重启成功！<span id='rsSecond'>3</span>秒后自动刷新");
                        time_task = setInterval("waitReload()", 1000);
                    }else{
                        alertInfo(data.message);
                    }
                },
                error: function (data) {
                    unDisableBtns();
                    errorInfo("当前环境无重启命令!");
                }
            });
        },function () {
            unDisableBtns();
        });
    });

    /*读秒*/
    function waitReload() {
        time_second = $("#rsSecond").text();
        if(time_second == 0){
            clearInterval(time_task);
            layer.closeAll();
            window.location.reload();
        }else{
            time_second--;
            $("#rsSecond").text(time_second);
        }
    }
    /*是否为空*/
    function isNull(str) {
        return str == null || str == "";
    }
    /*是否不为空*/
    function isNotNull(str) {
        return !isNull(str);
    }
    /*禁用所有按钮*/
    function disableBtns() {
        $(".container :button").each(function (obj) {
            $(this).attr("disabled", "disabled");
        });
    }
    /*解开所有按钮*/
    function unDisableBtns() {
        $(".container :button").each(function (obj) {
            $(this).removeAttr("disabled");
        });
    }
    /*警告信息*/
    function alertInfo(info){
        layer.alert(info,{
            title: title,
            icon: 0,
            closeBtn: 0, //不显示关闭按钮
            anim: 4,//从左翻滚
        });
    }
    /*异常信息*/
    function errorInfo(info) {
        layer.alert(info,{
            title: title,
            icon: 2,
            closeBtn: 0, //不显示关闭按钮
            anim: 6,//抖动
        });
    }
    /*成功信息*/
    function successInfo(info) {
        layer.alert(info,{
            title: title,
            closeBtn: 0, //不显示关闭按钮
            icon: 1,
            anim: 0,
        });
    }

</script>
